package top.aicey.ai.sparring.controller;

import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import top.aicey.ai.sparring.common.constants.ErrorConstants;
import top.aicey.ai.sparring.common.holder.UserHolder;
import top.aicey.ai.sparring.common.utils.BaseResponseUtil;
import top.aicey.ai.sparring.dto.model.BaseResponse;
import top.aicey.ai.sparring.dto.res.EvaluationUserSceneHistoryResponse;
import top.aicey.ai.sparring.entity.SceneInstanceEvaluation;
import top.aicey.ai.sparring.service.ISceneInstanceEvaluationService;

/**
 * <p>
 * 用户评价内容 前端控制器
 * </p>
 *
 * @author 白杨
 * @since 2024-12-19
 */
@Controller
@RequestMapping("/v3/sparing/trainingSceneUserEvaluation")
public class TrainingSceneUserEvaluationAdminController {

    @Autowired
    private ISceneInstanceEvaluationService sceneInstanceEvaluationService;


    @PostMapping(value = "/list")
    public BaseResponse<PageInfo<SceneInstanceEvaluation>> list(
            @RequestParam("scene_id") Long sceneId,
            @RequestParam(value = "user_id",required = false) Long userId,
            @RequestParam(value = "pageNumber", defaultValue = "1", required = false) Integer pageNumber,
            @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize
            ){
        if (Objects.isNull(sceneId)){
            return BaseResponseUtil.buildSuccessResponse(ErrorConstants.INVALID_PARAMS);
        }

        String moduleId = UserHolder.getUser().getModuleId();

        PageInfo<SceneInstanceEvaluation> page = sceneInstanceEvaluationService.pageByParams(pageNumber, pageSize, moduleId, sceneId, userId);
        return BaseResponseUtil.buildSuccessResponse(page);
    }


    @ApiOperation(value = "读取用户场景练习历史记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "scene_id",value = "场景id",required = true),
            @ApiImplicitParam(name = "user_id",value = "用户id",required = true),
            @ApiImplicitParam(name = "limit",value = "限制条数",defaultValue = "20",required = false),
            @ApiImplicitParam(name = "x-access-token",value = "token",required = true,paramType = "header")
    })
    @GetMapping(value = "/scene/user/history")
    public BaseResponse<List<EvaluationUserSceneHistoryResponse>> sceneHistory(@RequestParam("scene_id") Long sceneId,@RequestParam("user_id") String userId, @RequestParam(value = "limit",defaultValue = "20")Integer limit){
        if (Objects.isNull(sceneId) || sceneId < 0 || StringUtils.isEmpty(userId)){
            return BaseResponseUtil.buildSuccessResponse(ErrorConstants.INVALID_PARAMS);
        }

        List<EvaluationUserSceneHistoryResponse> list = sceneInstanceEvaluationService.sceneHistory(sceneId,userId,limit);

        return BaseResponseUtil.buildSuccessResponse(list);
    }

}
